<admintpl file="header" />
<style>
    .uploadList ul li{
        list-style: none;
    }
    .uploadList ul li img{
        max-height: 90px;
    }
    .field_left{
        width: 59%;
        float: left;
        margin-top: 40px;
        /*background: #D8D8D8;*/
        padding-top: 2%;
    }
    .field_left:last-child{
        width: 40%;
        margin-left: 1%;
    }
    #content{
     width: 100%;
    }
</style>
<script type="text/javascript" src="__PUBLIC__/uploadify/jquery.uploadify.min.js"></script>
<link rel="stylesheet" href="__PUBLIC__/uploadify/uploadify.css">
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li ><a href="{:U('Product/edit')}">添加品牌</a></li>
        <li class="active" ><a href="{:U('Product/edit',array('id'=>$_GET['id']))}"> 品牌列表 </a></li>
    </ul>
    <form action="{:U('Product/edit')}" method="post" class="form-horizontal js-ajax-forms" enctype="multipart/form-data">
        <fieldset style="overflow: hidden;">
            <div class="field_left">
                <div class="control-group">
                    <label class="control-label"> 商品名称 </label>
                    <div class="controls">
                        <input type="text" name="title" value="{$data['title']}" placeholder="请输入品牌名称">
                        <span class="form-required">*</span>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"> 商品描述  </label>
                    <div class="controls">
                        <textarea name="desc" id="" style="width: 480px;height: 60px;resize: none" placeholder="请输入商品描述">{$data['desc']}</textarea>
                        <!--<input type="text" name="desc" placeholder="请输入商品描述">-->
                        <span class="form-required">(副标题)</span>
                </div>
                </div>
                <div class="control-group">
                    <label class="control-label"> 首页推荐 </label>
                    <div class="controls" style="padding-left: 12px;">
                        否  <input type="radio" name="recommend" <if condition="$data['recommend'] eq 0">checked</if> value="0"> &nbsp;&nbsp;&nbsp;&nbsp;
                        是  <input type="radio" name="recommend" <if condition="$data['recommend'] eq 1">checked</if>  value="1">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"> 是否热卖 </label>
                    <div class="controls" style="padding-left: 12px;">
                        否  <input type="radio" name="hot" <if condition="$data['hot'] eq 0">checked</if>  value="0"> &nbsp;&nbsp;&nbsp;&nbsp;
                        是  <input type="radio" name="hot" <if condition="$data['hot'] eq 1">checked</if>  value="1">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"> 商品分类 </label>
                    <div class="controls">
                        <select name="category_id" id="category">
                            <option value="0">请选择分类</option>
                            <foreach name="categories" item="i">
                                <option value="{$i['term_id']}" <if condition="$i['term_id'] eq $data['category_id']">selected</if> >{$i['name']}</option>
                            </foreach>
                        </select>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"> 品牌 </label>
                    <div class="controls">
                        <select name="brand_id" id="brand">
                            <option value="0">请选择品牌</option>
                            <foreach name="brands" item="i">
                                <option value="{$i['id']}" <if condition = "$data['brand_id'] eq $i['id']" >selected</if> >{$i['title']}</option>
                            </foreach>
                        </select>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"> 价格 </label>
                    <div class="controls">
                        <input type="text" name="price" value="{$data['price']}">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"> 促销价格 </label>
                    <div class="controls">
                        <input type="text" name="price_plus" value="{$data['price_plus']}">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"> 市场价 </label>
                    <div class="controls">
                        <input type="text" name="bazar_price" value="{$data['bazar_price']}">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"> 库存 </label>
                    <div class="controls">
                        <input type="text" name="stock" value="{$data['stock']}">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"> 已销售 </label>
                    <div class="controls">
                        <input type="text" name="sold" value="{$data['sold']}">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"> 最小起订量 </label>
                    <div class="controls">
                        <input type="text" name="start_num" value="{$data['start_num']}">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"> 加减间隔 </label>
                    <div class="controls">
                        <input type="text" name="step" value="{$data['stock']}">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"> 单位 (默认 ：个) </label>
                    <div class="controls">
                        <input type="text" name="unit" value="{$data['unit']?$data['unit']:'个'}">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"> 商品详情 </label>
                    <div class="controls">
                        <script type="text/plain" id="content" name="details">{$data['details']|htmlspecialchars_decode}</script>
                    </div>
                </div>
            </div>
            <div class="field_left">
                <div class="control-group" style="margin-bottom: 40px;">
                    <label class="control-label"> 商品主图 </label>
                    <div class="controls">
                        <div lab="uploadFile">

                            <input id="image" type="file" multiple="false">
                            <script type="text/javascript">
                                $(function() {
                                    var path2 = "{$data['image']}";
                                    $('#image').uploadify({
                                        'formData'    : {          //POST数据
                                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
                                        },
                                        'fileTypeDesc' : '上传文件',//上传描述
                                        'fileTypeExts' : '*.jpeg;,*.jpg;*.png,*.JPEG;,*.JPG;*.PNG',
                                        'swf'      : '__PUBLIC__/uploadify/uploadify.swf',
                                        'uploader' : "{:U('User/File/upload')}",
                                        'buttonText':'选择文件',
                                        'fileSizeLimit' : '2048KB',
                                        'uploadLimit' : 1,//上传文件数
                                        'width':90,
                                        'height':36,
                                        'successTimeout':10,//等待服务器响应时间
                                        'removeTimeout' : 0.2,//成功显示时间
                                        'onUploadSuccess' : function(file, data, response) {
                                            //转为json
                                            data=$.parseJSON(data);
                                            //获得图片地址
                                            var imageUrl = data.url;
                                            var li="<li path='"+data.path+"' url='"+data.url+"'><img src='__ROOT__"+imageUrl+"'/><input type='hidden' name='image' value='"+imageUrl+"'/></li>";
                                            $("#uploadLogoBack ul").html(li);
                                        }
                                    });
                                });
                            </script>
                            <div id="uploadLogoBack" class="uploadList">
                                <ul>
                                    <li path="{$data[image]}" url="{$data['image']}"><img src="{$data[image]}"/><input type='hidden' name='image' value="{$data[image]}"/>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label"> 轮播图 </label>
                    <div class="controls">
                        <div lab="uploadFile">

                            <input id="di_card_back" type="file" multiple="false">
                            <script type="text/javascript">
                                $(function() {
//                                    var path2 = "{$data['logo']}";
                                    $('#di_card_back').uploadify({
                                        'formData'    : {          //POST数据
                                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
                                        },
                                        'fileTypeDesc' : '上传文件',//上传描述
                                        'fileTypeExts' : '*.jpeg;,*.jpg;*.png,*.JPEG;,*.JPG;*.PNG',
                                        'swf'      : '__PUBLIC__/uploadify/uploadify.swf',
                                        'uploader' : "{:U('User/File/upload')}",
                                        'buttonText':'选择文件',
                                        'fileSizeLimit' : '2048KB',
                                        'uploadLimit' : 10,//上传文件数
                                        'width':90,
                                        'height':36,
                                        'successTimeout':10,//等待服务器响应时间
                                        'removeTimeout' : 0.2,//成功显示时间
                                        'onUploadSuccess' : function(file, data, response) {
                                            //转为json
                                            data=$.parseJSON(data);
                                            //获得图片地址
                                            var imageUrl = data.url;
                                            var li="<li class='slider' slider_id='0' style='margin-bottom: 8px;'  path='"+data.path+"' url='"+data.url+"'><img src='__ROOT__"+imageUrl+"'/><input type='hidden' name='slider[]' value='"+imageUrl+"'/></li>";
                                            $("#uploadImgsBack ul").append(li);
                                        }
                                    });
                                });
                            </script>
                            <div id="uploadImgsBack" class="uploadList">
                                <ul>
                                    <foreach name="data['sliders']" item="i">
                                        <li class="slider" slider_id = "{$i['id']}" style="margin-bottom: 8px;" path="{$i['path']}" url="{$i['path']}">
                                            <img src="{$i['path']}"/>
                                            <input type='hidden' name='slider[]' value="{$i['path']}"/>
                                            <input type="hidden" name="slider_id[]" value="{$i['id']}" >
                                        </li>
                                    </foreach>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </fieldset>
        <input type="hidden" value="{$_GET['id']}" name="id">
        <div class="form-actions">
            <button class="btn btn-primary js-ajax-submit" type="submit">{:L("SAVE")}</button>
            <a class="btn" href="javascript:history.back(-1);">{:L('BACK')}</a>
        </div>
    </form>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
    var editorcontent = new baidu.editor.ui.Editor();
    editorcontent.render('content');
</script>
<script>
    $(function(){
      $(".slider").live('click',function(){
          var id = $(this).attr('slider_id');
          var path = $(this).attr('url');
          var that = this;
          if(confirm("确定删除这张图片吗？")){
              $.post("{:U('File/delete')}",{
                  id:id,
                  path:path
              },function(data){
                  if(data.code == 1){
                      $(that).remove();
                  }
              })
          }
      })
    })
</script>
</body>
</html>